package com.mall.module.system.controller;

import com.github.pagehelper.PageInfo;
import com.mall.common.result.Result;
import com.mall.module.system.domain.entity.SysConfig;
import com.mall.module.system.service.SysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统配置控制器
 */
@Api(tags = "系统配置接口")
@RestController
@RequestMapping("/api/system/config")
public class SysConfigController {
    
    @Autowired
    private SysConfigService configService;
    
    /**
     * 获取配置列表
     */
    @ApiOperation(value = "获取配置列表")
    @GetMapping("/list")
    public Result<PageInfo<SysConfig>> list(
            @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页记录数", defaultValue = "10") @RequestParam(defaultValue = "10") Integer pageSize,
            @ApiParam(value = "配置键") @RequestParam(required = false) String configKey,
            @ApiParam(value = "配置名称") @RequestParam(required = false) String configName) {
        PageInfo<SysConfig> pageInfo = configService.listConfigPage(pageNum, pageSize, configKey, configName);
        return Result.success(pageInfo);
    }
    
    /**
     * 获取配置详情
     */
    @ApiOperation(value = "获取配置详情")
    @GetMapping("/{id}")
    public Result<SysConfig> getInfo(@ApiParam(value = "配置ID", required = true) @PathVariable Long id) {
        SysConfig config = configService.getConfigById(id);
        return Result.success(config);
    }
    
    /**
     * 根据键获取配置
     */
    @ApiOperation(value = "根据键获取配置")
    @GetMapping("/key/{configKey}")
    public Result<SysConfig> getConfigByKey(@ApiParam(value = "配置键", required = true) @PathVariable String configKey) {
        SysConfig config = configService.getConfigByKey(configKey);
        return Result.success(config);
    }
    
    /**
     * 新增配置
     */
//    @ApiOperation(value = "新增配置")
//    @PostMapping
//    public Result<Void> add(@ApiParam(value = "配置信息", required = true) @RequestBody SysConfig config) {
//        boolean result = configService.addConfig(config);
//        return result ? Result.success() : Result.failed("新增配置失败");
//    }
//
//    /**
//     * 修改配置
//     */
//    @ApiOperation(value = "修改配置")
//    @PutMapping
//    public Result<Void> update(@ApiParam(value = "配置信息", required = true) @RequestBody SysConfig config) {
//        boolean result = configService.updateConfig(config);
//        return result ? Result.success() : Result.failed("修改配置失败");
//    }
//
//    /**
//     * 删除配置
//     */
//    @ApiOperation(value = "删除配置")
//    @DeleteMapping("/{id}")
//    public Result<Void> delete(@ApiParam(value = "配置ID", required = true) @PathVariable Long id) {
//        boolean result = configService.deleteConfig(id);
//        return result ? Result.success() : Result.failed("删除配置失败");
//    }
//
//    /**
//     * 批量删除配置
//     */
//    @ApiOperation(value = "批量删除配置")
//    @DeleteMapping("/batch")
//    public Result<Void> batchDelete(@ApiParam(value = "配置ID数组", required = true) @RequestBody List<Long> ids) {
//        boolean result = configService.deleteConfigByIds(ids);
//        return result ? Result.success() : Result.failed("批量删除配置失败");
//    }
} 